﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Media.Imaging;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Plumbing.Model;
using YArchitech.Revit;
using HYPreviewerControl;

namespace YArchitech.Plumbing
{
	public partial class FormWares : System.Windows.Forms.Form
	{
		public FormWares(Autodesk.Revit.DB.Document _doc, UIDocument _uidco, UIApplication _uiApp)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.doc = _doc;
			this.uiDoc = _uidco;
			this.uiApp = _uiApp;
			base.Icon = Resource.YArchitechIcon;
			this.imgW = this.imgListWares.ImageSize.Width;
			this.imgH = this.imgListWares.ImageSize.Height;
			this.isSymbolChanged = true;
			WinDPIManager.GetWinFormXYDpi(ref this.dXScale, ref this.dYScale);
			base.Size = new System.Drawing.Size(Convert.ToInt32(626.0 * this.dXScale), Convert.ToInt32(434.0 * this.dYScale));
			if ((int)this.doc.ActiveView.ViewType == 4)
			{
				this.btnWall.Enabled = false;
				this.btnWare.Enabled = false;
			}
			try
			{
				this.LoadDatas();
				this.InitWares();
				this.InitUserSetting();
			}
			catch (Exception)
			{
			}
		}

		private void InitUserSetting()
		{
			this.rb2D.Checked = true;
			if (this.userSetting.GetValue("LayWares", "IsCurrentPro") != "")
			{
				if (this.userSetting.GetValue("LayWares", "IsCurrentPro") == "True")
				{
					this.rbCurPro.Checked = true;
					this.rb3D.Checked = true;
				}
				else
				{
					this.rbFamilySymbol.Checked = true;
					if (this.userSetting.GetValue("LayWares", "Is2D") != "")
					{
						if (this.userSetting.GetValue("LayWares", "Is2D") == "True")
						{
							this.rb2D.Checked = true;
						}
						else
						{
							this.rb3D.Checked = true;
						}
					}
				}
			}
			if (this.userSetting.GetValue("LayWares", "WareType") != "")
			{
				for (int i = 0; i < this.lbWareTypes.Items.Count; i++)
				{
					if (this.lbWareTypes.Items[i].ToString() == this.userSetting.GetValue("LayWares", "WareType"))
					{
						this.lbWareTypes.SelectedIndex = i;
						break;
					}
				}
			}
			if (this.userSetting.GetValue("LayWares", this.lbWareTypes.SelectedItem.ToString() + "Elevation") != "")
			{
				this.txtOffset.Text = this.userSetting.GetValue("LayWares", this.lbWareTypes.SelectedItem.ToString() + "Elevation");
			}
			if (this.userSetting.GetValue("LayWares", "Ware") != "")
			{
				this.lvWares.Items[Convert.ToInt32(this.userSetting.GetValue("LayWares", "Ware"))].Selected = true;
			}
			if (this.rb2D.Checked)
			{
				this.showView = false;
				this.btnPreview.Enabled = false;
				this.btnPreview.Text = "预览》";
				return;
			}
			this.btnPreview.Enabled = true;
		}

		private void InitWares()
		{
			this.lbWareTypes.Items.Clear();
			bool flag = false;
			bool flag2 = false;
			if (!this.rbCurPro.Checked)
			{
				using (List<Ware>.Enumerator enumerator = this.wares.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Ware ware = enumerator.Current;
						if (!this.lbWareTypes.Items.Contains(ware.category))
						{
							if (ware.category != "其它")
							{
								if (ware.category != "地漏")
								{
									this.lbWareTypes.Items.Add(ware.category);
								}
								else
								{
									flag2 = true;
								}
							}
							else
							{
								flag = true;
							}
						}
					}
					goto IL_18D;
				}
			}
			this.lbWareTypes.Items.Add("蹲便器");
			this.lbWareTypes.Items.Add("坐便器");
			this.lbWareTypes.Items.Add("沐浴");
			this.lbWareTypes.Items.Add("洗涤盆和拖布池");
			this.lbWareTypes.Items.Add("洗脸盆");
			this.lbWareTypes.Items.Add("洗衣机");
			this.lbWareTypes.Items.Add("小便器");
			this.lbWareTypes.Items.Add("浴缸");
			this.lbWareTypes.Items.Add("地漏");
			this.lbWareTypes.Items.Add("其它");
			IL_18D:
			if (flag2)
			{
				this.lbWareTypes.Items.Add("地漏");
			}
			if (flag)
			{
				this.lbWareTypes.Items.Add("其它");
			}
			this.lbWareTypes.SetSelected(0, true);
		}

		private void LoadImages()
		{
			try
			{
				this.lvWares.Items.Clear();
				this.imgListWares.Images.Clear();
				string b = this.lbWareTypes.SelectedItem.ToString();
				bool flag = true;
				if (this.rb3D.Checked)
				{
					flag = false;
				}
				int num = 0;
				List<Ware> list = new List<Ware>();
				if (this.rbCurPro.Checked)
				{
					using (List<Element>.Enumerator enumerator = new FilteredElementCollector(this.doc).OfClass(typeof(FamilySymbol)).ToElements().ToList<Element>().GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							Element element = enumerator.Current;
							if (element.Category.Name == "卫浴装置" || element.Category.Name == "地漏")
							{
								Ware w = new Ware(this.GetCategoryName((element as FamilySymbol).GetFamilyNameBySymbol()), element as FamilySymbol);
								if ((element as FamilySymbol).Family.Name.Contains("2D"))
								{
									w.is2d = true;
								}
								else
								{
									w.is2d = false;
								}
								w.family = (element as FamilySymbol).Family.Name + ".rfa";
								if (!list.Any((Ware item) => item.family == w.family))
								{
									list.Add(w);
								}
							}
						}
						goto IL_197;
					}
				}
				list = this.wares;
				IL_197:
				if (list.Count >= 1)
				{
					foreach (Ware ware in list)
					{
						if (ware.category == b && ware.is2d == flag)
						{
							try
							{
								string text = ware.family.Substring(0, ware.family.LastIndexOf(".rfa"));
								Image image;
								if (this.rbCurPro.Checked)
								{
									FamilySymbol familySymbol = ware.fs;
									if (!File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + ".bmp")))
									{
										if (!File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + "_export - 楼层平面 - 参照标高.jpg")))
										{
											Document document = this.doc.EditFamily(familySymbol.Family);
											ImageExportOptions imageExportOptions = new ImageExportOptions();
                                            imageExportOptions.FitDirection = (FitDirectionType)1;
                                            imageExportOptions.HLRandWFViewsFileType = (ImageFileType)1;
                                            imageExportOptions.ImageResolution = (ImageResolution)3;
											imageExportOptions.ShouldCreateWebSite = false;
                                            imageExportOptions.ExportRange = (ExportRange)2;
                                            imageExportOptions.ZoomType = (ZoomFitType)1;
											imageExportOptions.Zoom = 7;
											imageExportOptions.FilePath = Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + "_export");
											ElementId elementId = null;
											FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
											FilteredElementIterator elementIterator = filteredElementCollector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator();
											elementIterator.Reset();
											while (elementIterator.MoveNext())
											{
												Element element2 = elementIterator.Current;
												Autodesk.Revit.DB.View view = element2 as Autodesk.Revit.DB.View;
												if (view != null && !view.IsTemplate && (int)view.ViewType == 1 && view.Name == "参照标高")
												{
													elementId = view.Id;
													break;
												}
											}
											Transaction transaction = new Transaction(document, "deleteLines");
											transaction.Start();
											List<Element> list2 = filteredElementCollector.OfClass(typeof(ReferencePlane)).ToElements().ToList<Element>();
											List<Element> list3 = filteredElementCollector.OfClass(typeof(Dimension)).ToElements().ToList<Element>();
											foreach (Element elem in list2)
											{
												document.DeleteElement(elem);
											}
											foreach (Element elem2 in list3)
											{
												document.DeleteElement(elem2);
											}
											document.Regenerate();
											transaction.Commit();
											if (!(null != elementId))
											{
												continue;
											}
											imageExportOptions.SetViewsAndSheets(new List<ElementId>
											{
												elementId
											});
											document.ExportImage(imageExportOptions);
											image = Image.FromFile(imageExportOptions.FilePath + " - 楼层平面 - 参照标高.jpg", true);
										}
										else
										{
											image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + "_export - 楼层平面 - 参照标高.jpg"), true);
										}
									}
									else
									{
										image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + ".bmp"), true);
									}
								}
								else
								{
									image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentSanitary", text + ".bmp"), true);
								}
								if (image != null)
								{
									this.imgListWares.Images.Add(image);
									ListViewItem listViewItem = new ListViewItem();
									listViewItem.ImageIndex = num;
									listViewItem.Text = text;
									listViewItem.Tag = ware;
									this.lvWares.Items.Add(listViewItem);
									num++;
								}
							}
							catch (Exception ex)
							{
								YJKMessageBox.Show(ex.Message);
							}
						}
					}
					if (this.lvWares.Items.Count > 0)
					{
						this.lvWares.Select();
						this.lvWares.Items[0].Selected = true;
					}
				}
			}
			catch (Exception ex2)
			{
				YJKMessageBox.Show(ex2.Message);
			}
		}

		private Bitmap GetBitmap(BitmapSource source)
		{
			Bitmap bitmap = new Bitmap(source.PixelWidth, source.PixelHeight, PixelFormat.Format32bppPArgb);
			BitmapData bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb);
			source.CopyPixels(Int32Rect.Empty, bitmapData.Scan0, bitmapData.Height * bitmapData.Stride, bitmapData.Stride);
			bitmap.UnlockBits(bitmapData);
			return bitmap;
		}

		private Document Get3DPreviewPicture(string path)
		{
			Document document = null;
			try
			{
				document = this.uiApp.Application.OpenDocumentFile(path);
				this.m_GeneralDocumentList.Add(document);
			}
			catch (Exception)
			{
                System.Windows.Forms.MessageBox.Show("文档打开出错", "盈建科提示");
			}
			return document;
		}

		public void CloseDocuments()
		{
			foreach (Autodesk.Revit.DB.Document document in this.m_GeneralDocumentList)
			{
				try
				{
					document.Close(false);
				}
				catch (Exception)
				{
				}
			}
		}

		private void initPreviewControl(FamilySymbol fs)
		{
			Document subdoc = this.doc.EditFamily(fs.Family);
			this.Update3DView(subdoc);
		}

		private void initPreviewControl(string szFullName)
		{
			Document subdoc = this.Get3DPreviewPicture(szFullName);
			this.m_GeneralDocumentList.Add(this.doc);
			this.Update3DView(subdoc);
		}

		private string GetCategoryName(string familyName)
		{
			if (familyName.Contains("地漏"))
			{
				return "地漏";
			}
			if (familyName.Contains("蹲便") || (familyName.Contains("蹲") && familyName.Contains("大便")))
			{
				return "蹲便器";
			}
			if (familyName.Contains("坐便") || (familyName.Contains("坐") && familyName.Contains("大便")))
			{
				return "坐便器";
			}
			if (familyName.Contains("沐浴") || familyName.Contains("淋浴"))
			{
				return "沐浴";
			}
			if (familyName.Contains("洗涤") || familyName.Contains("拖布") || familyName.Contains("污水"))
			{
				return "洗涤盆和拖布池";
			}
			if (familyName.Contains("脸"))
			{
				return "洗脸盆";
			}
			if (familyName.Contains("小便"))
			{
				return "小便器";
			}
			if (familyName.Contains("浴缸") || familyName.Contains("浴盆"))
			{
				return "浴缸";
			}
			if (familyName.Contains("洗衣机"))
			{
				return "洗衣机";
			}
			return "其它";
		}

		private void Update3DView(Autodesk.Revit.DB.Document subdoc)
		{
			PreviewControl previewControl = this.elementHost.Child as PreviewControl;
			if (subdoc == null)
			{
				if (previewControl != null)
				{
					previewControl.Dispose();
					previewControl = null;
				}
				return;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(subdoc);
			filteredElementCollector.OfClass(typeof(Autodesk.Revit.DB.View));
			IEnumerable<Autodesk.Revit.DB.View> enumerable = from Element f in filteredElementCollector
			where (f as Autodesk.Revit.DB.View).CanBePrinted
			select f as Autodesk.Revit.DB.View;
			Autodesk.Revit.DB.View view = null;
			foreach (Autodesk.Revit.DB.View view2 in enumerable)
			{
				if ((int)view2.ViewType == 4 && view2.Name == "{3D}")
				{
					view = view2;
					break;
				}
			}
			if (view == null)
			{
				foreach (Autodesk.Revit.DB.View view3 in enumerable)
				{
					if ((int)view3.ViewType == 4)
					{
						view = view3;
						break;
					}
				}
			}
			if (view == null)
			{
				foreach (Autodesk.Revit.DB.View view4 in enumerable)
				{
					if ((int)view4.ViewType == 1)
					{
						view = view4;
						break;
					}
				}
			}
			if (view == null)
			{
				if (previewControl != null)
				{
					previewControl.Dispose();
					previewControl = null;
				}
				return;
			}
			if (previewControl != null)
			{
				previewControl.Dispose();
			}
			this.elementHost.Child = new PreviewControl(subdoc, view.Id);
		}

		private void btnWall_Click(object sender, EventArgs e)
		{
			if (this.lvWares.SelectedItems.Count < 1)
			{
				YJKMessageBox.Show("请选择一个要布置的族！");
				return;
			}
			if (!(this.txtOffset.Text != string.Empty) || this.txtOffset.Text == null)
			{
				YJKMessageBox.Show("相对标高不能为空，请重新输入！");
				return;
			}
			this.layType = 1;
			this.elevation = Convert.ToDouble(this.txtOffset.Text) * 1000.0;
			this.SetUserData();
			FormWareByWall formWareByWall = new FormWareByWall();
			formWareByWall.ShowDialog();
			if (formWareByWall.DialogResult == DialogResult.OK)
			{
				this.equipCount = formWareByWall.equipCount;
				this.wallFaceDistance = formWareByWall.wallFaceDistance;
				this.equipDistance = formWareByWall.equipDistance;
				this.wallPointDistance = formWareByWall.wallPointDistance;
				base.DialogResult = DialogResult.OK;
				return;
			}
		}

		private void LoadDatas()
		{
			foreach (object obj in this.sfdr.GetWares().Rows)
			{
				DataRow dataRow = (DataRow)obj;
				try
				{
					this.wares.Add(new Ware(Convert.ToInt32(dataRow["Id"]), dataRow["Name"].ToString(), dataRow["Family"].ToString(), dataRow["FamilySymbol"].ToString(), dataRow["Category"].ToString(), dataRow["Version"].ToString(), Convert.ToBoolean(dataRow["Is2D"].ToString())));
				}
				catch
				{
				}
			}
		}

		private void lvWares_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lvWares.SelectedItems.Count > 0)
			{
				Ware ware = (Ware)this.lvWares.SelectedItems[0].Tag;
				if (this.rbCurPro.Checked)
				{
					this.fs = ware.fs;
					if (this.btnPreview.Text == "预览《")
					{
						this.initPreviewControl(this.fs);
					}
				}
				else
				{
					BuiltInCategory builtInCate = (BuiltInCategory)(-2001160);
					if (ware.category == "地漏")
					{
						builtInCate = (BuiltInCategory)(-2008055);
					}
					if (this.btnPreview.Text == "预览《")
					{
						string familyFullPath = this.sfdr.GetFamilyFullPath(ware.id, "EquipmentSanitary", ware.familySymbol, this.doc, builtInCate);
						this.initPreviewControl(familyFullPath);
					}
				}
				if (this.rbCurPro.Checked && this.fs != null)
				{
					if (YJKRevitTools.GetFamilyHost(this.fs) != 0)
					{
						this.btnWall.Enabled = false;
						this.btnWare.Enabled = false;
						return;
					}
					if ((int)this.doc.ActiveView.ViewType != 4)
					{
						this.btnWall.Enabled = true;
						this.btnWare.Enabled = true;
						return;
					}
				}
				else if ((int)this.doc.ActiveView.ViewType != 4)
				{
					this.btnWall.Enabled = true;
					this.btnWare.Enabled = true;
				}
			}
		}

		private void lbWareTypes_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.userSetting.GetValue("LayWares", this.lbWareTypes.SelectedItem.ToString() + "Elevation") != "")
			{
				this.txtOffset.Text = this.userSetting.GetValue("LayWares", this.lbWareTypes.SelectedItem.ToString() + "Elevation");
			}
			else
			{
				this.txtOffset.Text = "0";
				if (this.lbWareTypes.SelectedItem.ToString() == "洗脸盆")
				{
					this.txtOffset.Text = "0.8";
				}
			}
			this.LoadImages();
			if (this.lvWares.Items.Count > 0)
			{
				this.lvWares.Select();
				this.lvWares.Items[0].Selected = true;
			}
		}

		private void rb2D_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rb2D.Checked)
			{
				base.Size = new System.Drawing.Size(Convert.ToInt32(626.0 * this.dXScale), Convert.ToInt32(434.0 * this.dYScale));
				this.showView = false;
				this.btnPreview.Enabled = false;
				this.btnPreview.Text = "预览》";
			}
			else
			{
				this.btnPreview.Enabled = true;
			}
			this.LoadImages();
		}

		private void rbFamilySymbol_CheckedChanged(object sender, EventArgs e)
		{
			this.InitWares();
			this.LoadImages();
		}

		private void btnFree_Click(object sender, EventArgs e)
		{
			if (this.lvWares.SelectedItems.Count < 1)
			{
				YJKMessageBox.Show("请选择一个要布置的族！");
				return;
			}
			if (this.txtOffset.Text != string.Empty && this.txtOffset.Text != null)
			{
				this.layType = 0;
				this.elevation = Convert.ToDouble(this.txtOffset.Text) * 1000.0;
				this.SetUserData();
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Show("相对标高不能为空，请重新输入！");
		}

		protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
		{
			int num = 256;
			int num2 = 260;
			if ((msg.Msg == num | msg.Msg == num2) && keyData == Keys.Escape)
			{
				base.Dispose();
			}
			return false;
		}

		private List<CurveInfo> Get2DFamilyCurves(FamilySymbol fs)
		{
			List<CurveInfo> list = new List<CurveInfo>();
			try
			{
				Document document = this.doc.EditFamily(fs.Family);
				Autodesk.Revit.DB.View referenceView = this.GetReferenceView(document);
				if (referenceView == null)
				{
					return null;
				}
				List<Element> list2 = new List<Element>();
				List<Element> list3 = new List<Element>();
				foreach (Element element in new FilteredElementCollector(document, referenceView.Id).ToElements())
				{
					if (element.Category != null)
					{
						if (element is SymbolicCurve)
						{
							list2.Add(element);
						}
						else if (element is FamilyInstance)
						{
							if (element.Category.Id.IntegerValue == -2008055 || element.Category.Id.IntegerValue == -2001160)
							{
								list3.Add(element);
							}
						}
						else
						{
							Wall wall = element as Wall;
						}
					}
				}
				Options options = new Options();
				options.View = this.uiDoc.ActiveView;
				options.ComputeReferences = true;
				if (list.Count == 0)
				{
					foreach (Element element2 in list3)
					{
						List<GeometryObject> list4 = new List<GeometryObject>();
						foreach (GeometryObject item in (element2 as FamilyInstance).Symbol.get_Geometry(options))
						{
							list4.Add(item);
						}
						foreach (GeometryObject geometryObject in list4)
						{
							if (geometryObject is Arc || geometryObject is Line)
							{
								Curve curve = (Curve)geometryObject;
								if (curve.IsBound)
								{
									list.Add(new CurveInfo(curve, PenColor.PC_Black, 1f));
								}
							}
							else if (geometryObject is Solid)
							{
								Solid solid = geometryObject as Solid;
								if (!(solid == null))
								{
									foreach (object obj in solid.Edges)
									{
										Curve curve = ((Edge)obj).AsCurve();
										if (curve.IsBound)
										{
											list.Add(new CurveInfo(curve, PenColor.PC_Black, 1f));
										}
									}
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Show(ex.Message);
			}
			return list;
		}

		private static bool IsCoarse(int value)
		{
			return (value & 8206) == 8206;
		}

		private bool IsSymbolicCurveCoarse(int value)
		{
			return (value & 8192) == 8192;
		}

		private Autodesk.Revit.DB.View GetReferenceView(Autodesk.Revit.DB.Document sourceDocument)
		{
			FilteredElementIterator elementIterator = new FilteredElementCollector(sourceDocument).OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator();
			elementIterator.Reset();
			Autodesk.Revit.DB.View view = null;
			while (elementIterator.MoveNext())
			{
				Element element = elementIterator.Current;
				Autodesk.Revit.DB.View view2 = element as Autodesk.Revit.DB.View;
				if (view2 != null && !view2.IsTemplate && (int)view2.ViewType == 1)
				{
					view = view2;
					break;
				}
			}
			if (view == null)
			{
				while (elementIterator.MoveNext())
				{
					Element element2 = elementIterator.Current;
					Autodesk.Revit.DB.View view3 = element2 as Autodesk.Revit.DB.View;
					if (view3 != null && !view3.IsTemplate && (int)view3.ViewType == 2)
					{
						view = view3;
						break;
					}
				}
			}
			return view;
		}

		private void btnWare_Click(object sender, EventArgs e)
		{
			if (this.lvWares.SelectedItems.Count < 1)
			{
				YJKMessageBox.Show("请选择一个要布置的族！");
				return;
			}
			if (!(this.txtOffset.Text != string.Empty) || this.txtOffset.Text == null)
			{
				YJKMessageBox.Show("相对标高不能为空，请重新输入！");
				return;
			}
			this.layType = 2;
			this.elevation = Convert.ToDouble(this.txtOffset.Text) * 1000.0;
			this.SetUserData();
			FormWareByWare formWareByWare = new FormWareByWare();
			formWareByWare.ShowDialog();
			if (formWareByWare.DialogResult == DialogResult.OK)
			{
				this.distance = formWareByWare.distance;
				this.isByNumber = formWareByWare.isByNumber;
				this.wareCount = formWareByWare.wareCount;
				this.offset = formWareByWare.offset;
				base.DialogResult = DialogResult.OK;
				return;
			}
		}

		private void SetUserData()
		{
			this.userSetting.WriteValue("LayWares", "WareType", this.lbWareTypes.SelectedItem.ToString());
			this.userSetting.WriteValue("LayWares", "Ware", this.lvWares.SelectedItems[0].Index.ToString());
			this.userSetting.WriteValue("LayWares", this.lbWareTypes.SelectedItem.ToString() + "Elevation", this.txtOffset.Text);
			this.userSetting.WriteValue("LayWares", "Is2D", this.rb2D.Checked.ToString());
			this.userSetting.WriteValue("LayWares", "IsCurrentPro", this.rbCurPro.Checked.ToString());
		}

		private void btnPreview_Click(object sender, EventArgs e)
		{
			if (this.lvWares.SelectedItems.Count > 0)
			{
				Ware ware = (Ware)this.lvWares.SelectedItems[0].Tag;
				if (this.rbCurPro.Checked)
				{
					this.fs = ware.fs;
					this.initPreviewControl(this.fs);
				}
				else
				{
					BuiltInCategory builtInCate = (BuiltInCategory)(-2001160);
					if (ware.category == "地漏")
					{
						builtInCate = (BuiltInCategory)(-2008055);
					}
					string familyFullPath = this.sfdr.GetFamilyFullPath(ware.id, "EquipmentSanitary", ware.familySymbol, this.doc, builtInCate);
					this.initPreviewControl(familyFullPath);
				}
			}
			if (this.showView)
			{
				base.Size = new System.Drawing.Size(Convert.ToInt32(626.0 * this.dXScale), Convert.ToInt32(434.0 * this.dYScale));
				this.showView = false;
				this.btnPreview.Text = "预览》";
				return;
			}
			base.Size = new System.Drawing.Size(Convert.ToInt32(895.0 * this.dXScale), Convert.ToInt32(434.0 * this.dYScale));
			this.showView = true;
			this.btnPreview.Text = "预览《";
		}

		private void FormWares_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				return;
			}
			if (this.lvWares.SelectedItems.Count > 0)
			{
				Ware ware = (Ware)this.lvWares.SelectedItems[0].Tag;
				if (this.rbCurPro.Checked)
				{
					this.fs = ware.fs;
					return;
				}

                BuiltInCategory builtInCate = (BuiltInCategory)(-2001160);
                if (ware.category == "地漏")
                {
                    builtInCate = (BuiltInCategory)(-2008055);
                }
				this.fs = this.sfdr.GetFamilySymbolById(ware.id, "EquipmentSanitary", ware.familySymbol, this.doc, builtInCate);
			}
		}

		private const string tableName = "EquipmentSanitary";

		private List<CurveInfo> curves = new List<CurveInfo>();

		private UIDocument uiDoc;

		private UIApplication uiApp;

		private double dXScale = 1.0;

		private double dYScale = 1.0;

		private List<Document> m_GeneralDocumentList = new List<Document>();

		private bool showView;

		public bool isSymbolChanged;

		private SpaceFamilyDataReader sfdr = new SpaceFamilyDataReader();

		public double elevation;

		public int layType;

		public FamilySymbol fs;

		private List<Ware> wares = new List<Ware>();

		private Document doc;

		private int imgW;

		private int imgH;

		public int equipCount = 3;

		public int equipDistance;

		public int wallFaceDistance;

		public int wallPointDistance;

		public int distance;

		public int offset;

		public bool isByNumber;

		public int wareCount = 1;

		private UserSetting userSetting = new UserSetting();

		[Flags]
		public enum SymbolicCurveDetailLevelValue
		{
			Coarse = 8192,
			Medium = 16384,
			Fine = 32768
		}

		[Flags]
		public enum DetailLevelValue
		{
			Coarse = 8206,
			Medium = 16398,
			Fine = 32782
		}
	}
}
